<?php


namespace App\HttpController\Internet;

use App\Model\WeighbridgeListModel;
use EasySwoole\Validate\Validate;

class Weighbridge extends \App\HttpController\BaseInternet
{
    //参数校验
    protected function validateRule(?string $action): ?Validate
    {
        $v = new Validate();
        switch ($action) {

            case'getWeighbridgeList':
                $v->addColumn('pn', '页码')->required('参数不能缺少')->min(1);
                $v->addColumn('page_size', '每页条数')->required('参数不能缺少')->min(1);
                $v->addColumn('serial_number', '流水号')->required('参数不能缺少');
                $v->addColumn('license_plate', '车牌号')->required('参数不能缺少');
                $v->addColumn('cargo_name', '货名')->required('参数不能缺少');
                $v->addColumn('start_time', '开始时间')->required('参数不能缺少');
                $v->addColumn('end_time', '结束时间')->required('参数不能缺少');
                $v->addColumn('associated_waybill', '关联运单状态')->required('参数不能缺少');
                $v->addColumn('sorter_field', '排序字段')->required('参数不能缺少');
                $v->addColumn('sorter_order', '排序顺序')->required('参数不能缺少');
                break;
        }
        return $v;
    }
    //传入参数
    public function getWeighbridgeList()
    {
        $params = $this->paramData;
        foreach ($params as $k => $par_v) {
            $params[$k] = trim($par_v);
        }

        $par = [];
        $par['serial_number']=$params["serial_number"];
        $par['license_plate']=$params["license_plate"];
        $par['associated_waybill']=$params["associated_waybill"];
        $par['cargo_name']=$params["cargo_name"];
        $par['start_time']=$params["start_time"];
        $par['end_time']=$params["end_time"];
        $par['pn']=$params["pn"];
        $par['page_size']=$params["page_size"];
        $par['sorter_field']=$params["sorter_field"];
        $par['sorter_order']=$params["sorter_order"];
//        var_dump($par);

        $field = ['id','serial_number','license_plate','cargo_name',
            'suttle','weighing_time','associated_waybill','type','waybill_id'];
        $weighbridgelist = WeighbridgeListModel::create()->getWeighbridgeList($par,$field);
        //var_dump($weighbridgelist);

        $list=[];
        foreach ($weighbridgelist['data'] as $key => $value) {
            $result = [];
            $result['id'] = $value['id'];
            $result['serial_number'] = $value['serial_number'];
            $result['license_plate'] = $value['license_plate'];
            $result['cargo_name'] = $value['cargo_name'];
            $result['suttle'] = $value['suttle'];
            $result['weighing_time'] = $value['weighing_time'];
            $result['associated_waybill'] = $value['associated_waybill'];
            $result['type'] = $value['type'];
            $result['waybill_id'] = $value['waybill_id'];
            $list[]=$result;
        }
//        print_r($list);

        print_r(json_encode($list));
        //返回数据给前端
        var_dump("运行成功！！！");
        return $this->returnMsg($list,20000,'请求成功',['total' => $weighbridgelist['total']]);

    }

}